package cn.stylefeng.guns.modular.task.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.basic.service.BasicOperateService;
import cn.stylefeng.guns.modular.task.entity.TaskFeedback;
import cn.stylefeng.guns.modular.task.model.params.TaskFeedbackParam;
import cn.stylefeng.guns.modular.task.service.TaskFeedbackService;
import cn.stylefeng.guns.sys.modular.system.entity.User;
import cn.stylefeng.guns.sys.modular.system.service.UserService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;


/**
 * 作业反馈控制器
 *
 * @author zhucx
 * @Date 2021-06-25 14:10:23
 */
@Controller
@RequestMapping("/taskFeedback")
public class TaskFeedbackController extends BaseController {

    private String PREFIX = "/task/taskFeedback";

    @Autowired
    private TaskFeedbackService taskFeedbackService;

    @Autowired
    private BasicOperateService basicOperateService;

    @Autowired
    private UserService userService;

    /**
     * 跳转到主页面
     *
     * @author zhucx
     * @Date 2021-06-25
     */
    @RequestMapping("")
    public String index(Model model) {
    	User user = userService.getcurrentUser();
    	Long deptId = user.getDeptId();
    	Long deliverId = user.getDeliverId();
    	model.addAttribute("basicOperatelist", basicOperateService.findAvailableList(deptId,deliverId,user.getOperateId()));
        return PREFIX + "/taskFeedback.html";
    }

    /**
     * 新增页面
     *
     * @author zhucx
     * @Date 2021-06-25
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/taskFeedback_add.html";
    }

    /**
     * 编辑页面
     *
     * @author zhucx
     * @Date 2021-06-25
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/taskFeedback_edit.html";
    }

    /**
     * 新增接口
     *
     * @author zhucx
     * @Date 2021-06-25
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(TaskFeedbackParam taskFeedbackParam) {
        this.taskFeedbackService.add(taskFeedbackParam);
        return ResponseData.success();
    }

    /**
     * 编辑接口
     *
     * @author zhucx
     * @Date 2021-06-25
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(TaskFeedbackParam taskFeedbackParam) {
        this.taskFeedbackService.update(taskFeedbackParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     *
     * @author zhucx
     * @Date 2021-06-25
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(TaskFeedbackParam taskFeedbackParam) {
        this.taskFeedbackService.delete(taskFeedbackParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *
     * @author zhucx
     * @Date 2021-06-25
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(TaskFeedbackParam taskFeedbackParam) {
        TaskFeedback detail = this.taskFeedbackService.getById(taskFeedbackParam.getId());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     *
     * @author zhucx
     * @Date 2021-06-25
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(TaskFeedbackParam taskFeedbackParam,String condition ) {
    	User user = userService.getcurrentUser();
    	taskFeedbackParam.setDeptId(user.getDeptId());
    	taskFeedbackParam.setDeliverId(user.getDeliverId());
        return this.taskFeedbackService.findPageBySpec(taskFeedbackParam,condition,user.getOperateId());
    }

}


